package com.it.demo012;

public class Foodie extends Thread {
    private Desk desk;

    public Foodie(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while (true){
            synchronized (desk.getLook()){
                if(desk.getCount()==0){
                    break;
                }else {
                    if(desk.isFlag()){
                        //有
                        System.out.println("在吃");
                       desk.setFlag(false);
                  desk.getLook().notifyAll();
                desk.setCount(desk.getCount() -1);
                    }else {
                        //没有等待
                        //使用什么对象当锁，那么就必须用这个对象去调用等待和唤醒的方法
                        try {
                          desk.getLook().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            }
        }
    }
}
